package com.ticket.sass.admin.dto.output.admin;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.gson.Gson;
import com.ticket.sass.admin.model.KeyInfoModel;
import com.ticket.sass.admin.util.GsonUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;
import java.util.Objects;

/**
 * @author ywb
 * @date 2024-03-18 15:34
 */
@Data
@AllArgsConstructor
@ApiModel(value = "管理员详细信息")
public class AdminInfoOutput {
    @ApiModelProperty(value = "id")
    private Long id;
    
    @ApiModelProperty(value = "用户名")
    private String username;
    
    @ApiModelProperty(value = "头像")
    private String avatar = "https://cdn.eleadmin.com/20200610/avatar.jpg";
    
    @ApiModelProperty(value = "启用状态")
    private Boolean enable;
    
    @ApiModelProperty(value = "租户ID")
    private Long tenantId;
    
    @ApiModelProperty(value = "影院ID")
    private List<CinemaBrief> cinemas;
    
    public AdminInfoOutput() {
    }
    
    public AdminInfoOutput(Long id, String username, Boolean enable, Long tenantId, List<CinemaBrief> cinemas) {
        this.id = id;
        this.username = username;
        this.enable = enable;
        this.tenantId = tenantId;
        this.cinemas = cinemas;
    }
    
    public String toJson() {
        Gson instance = GsonUtil.getInstance();
        return instance.toJson(this);
    }
    
    @Data
    @ApiModel
    public static class CinemaBrief{
        private Long id;
        private String name;
        @JsonIgnore
        @ApiModelProperty(value = "影院LOGO")
        private String logo;
        
        @ApiModelProperty(value = "影院LOGO")
        private KeyInfoModel logoModel;
        
        public KeyInfoModel getLogoModel() {
            if (Objects.isNull(logo)){
                return null;
            }
            
            return new KeyInfoModel(logo.toString());
        }
        
        public CinemaBrief() {
        }
        
        public CinemaBrief(Long id, String name, String logo) {
            this.id = id;
            this.name = name;
            this.logo = logo;
        }
    }
}
